﻿#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
using namespace std;
const int N = 100010;
int a[N];
int main()
{
    int n, m;
    cin >> n >> m;
    for (int i = 1; i <= n; i++)
    {
        a[i] = i;
    }
    int j = 1;
    int k = n;
    while (n != 1)
    {
        for (int i = 1; i <= k; i++)
        {
            if (j == m && a[i] != 0)
            {
                a[i] = 0;
                j = 1;
                if (n == 1) break;
                n--;
            }
            if (a[i] != 0) j++;
        }
        if (n == 1) break;
    }
    int ret = 0;
    for (int i = 1; i <= k; i++)
    {
        if (a[i] != 0)
        {
            ret = a[i];
        }
    }
    cout << ret << endl;
    return 0;
}